from rest_framework.permissions import IsAdminUser,DjangoModelPermissions
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet
from django.contrib.auth.models import Permission, ContentType,Group

from ..serializers.permissions import PermissionSerialzier
from ..serializers.groups import  GroupSerialzier
from ..utils import PageNum


class GroupView(ModelViewSet):
    # 指定查询集
    queryset = Group.objects.all()
    # 指定序列化器
    serializer_class = GroupSerialzier
    # 指定权限
    permission_classes = [IsAdminUser,DjangoModelPermissions]
    # 指定分页器
    pagination_class = PageNum

    # 获取所有权限
    def simple(self, request):
        # 1、查询权限类型表，获取权限类型
        data = Permission.objects.all()
        # 2、序列化返回
        ser = PermissionSerialzier(data, many=True)
        return Response(ser.data)